package com.xbfinance.portal.service.impl;

import com.xbfinance.portal.dao.P2pProjectMapper;
import com.xbfinance.portal.pojo.po.P2pProject;
import com.xbfinance.portal.pojo.po.P2pProjectExample;
import com.xbfinance.portal.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ProjectServiceImpl implements ProjectService {

    @Autowired
    private P2pProjectMapper p2pProjectMapper;

    @Override
    public List<P2pProject> queryAllProject() {

        P2pProjectExample example = new P2pProjectExample();

        List<P2pProject> p2pProjects = p2pProjectMapper.selectByExample(example);

        return p2pProjects;
    }

    @Override
    public List<P2pProject> queryProjectByName(String name) {

        P2pProjectExample example = new P2pProjectExample();

        example.createCriteria().andPronameLike("%"+name+"%");

        List<P2pProject> list = p2pProjectMapper.selectByExample(example);

        return list;
    }

    @Override
    public P2pProject queryProjectByPid(Long proid) {

        P2pProjectExample example = new P2pProjectExample();

        example.createCriteria().andProidEqualTo(proid);

        List<P2pProject> list = p2pProjectMapper.selectByExample(example);

        return list.get(0);
    }
}
